home *** CD-ROM | disk | FTP | other *** search
- package com.ibm.xml.parser;
-
- import java.io.BufferedReader;
- import java.io.File;
- import java.io.IOException;
- import java.io.PrintWriter;
- import java.io.Reader;
- import java.net.MalformedURLException;
- import java.net.URL;
- import java.util.Hashtable;
- import java.util.Stack;
- import java.util.StringTokenizer;
-
- public class Stderr implements ErrorListener, StreamProducer {
- private static final boolean DEBUG_ENTITY_RESOLUTION = false;
- public static PrintWriter printer;
- protected String name;
- protected URL url;
- protected Stack stack = new Stack();
- protected Hashtable catalog;
- protected boolean isPrintWarning = true;
- protected String publicId;
- protected String systemId;
-
- public Stderr(String var1) {
- this.name = var1;
-
- try {
- this.url = new URL(this.name);
- this.systemId = this.url.toString();
- } catch (MalformedURLException var5) {
- try {
- this.url = file2URL(var1);
- this.systemId = this.url.toString();
- } catch (MalformedURLException var3) {
- throw new LibraryException("Stderr#Stderr(): Internal Error: " + var5);
- } catch (SecurityException var4) {
- printer.println("Specify a complete URL");
- }
- }
- }
-
- public void setPrintWarning(boolean var1) {
- this.isPrintWarning = var1;
- }
-
- public static URL file2URL(String var0) throws MalformedURLException {
- var0 = var0.replace(File.separatorChar, '/');
- String var1 = System.getProperty("user.dir").replace(File.separatorChar, '/') + "/";
- if (var1.charAt(0) != '/') {
- var1 = "/" + var1;
- }
-
- URL var2 = new URL("file", "", var1);
- if (var0.length() >= 2 && var0.charAt(1) == ':') {
- char var3 = Character.toUpperCase(var0.charAt(0));
- if (var3 >= 'A' && var3 <= 'Z') {
- var0 = "file:///" + var0;
- }
- }
-
- return new URL(var2, var0);
- }
-
- public int error(String var1, int var2, int var3, Object var4, String var5) {
- if (var1 == null) {
- var1 = this.name;
- }
-
- if (var3 > 0) {
- --var3;
- }
-
- if (this.isPrintWarning || !(var4 instanceof String) || !((String)var4).startsWith("W_")) {
- printer.println(var1 + ": " + var2 + ", " + var3 + ": " + var5);
- }
-
- printer.flush();
- return 1;
- }
-
- private String URI2URL(String var1) throws IOException {
- if (var1.length() > 4 && var1.substring(0, 4).equalsIgnoreCase("urn:")) {
- String var2 = Util.normalizeURN(var1);
- if (this.catalog == null || !this.catalog.containsKey(var2)) {
- throw new IOException("Can't resolve URN: " + var1);
- }
-
- var1 = (String)this.catalog.get(var2);
- }
-
- return var1;
- }
-
- public Source getInputStream(String var1, String var2, String var3) throws IOException {
- this.publicId = var2;
- if (var2 != null && this.catalog != null && this.catalog.containsKey(var2)) {
- String var4 = (String)this.catalog.get(var2);
- var4 = this.URI2URL(var4);
- URL var5 = new URL(this.url, var4);
-
- try {
- Source var6 = new Source(var5.openStream());
- this.stack.push(this.url);
- this.url = var5;
- this.systemId = var4;
- return var6;
- } catch (IOException var7) {
- }
- }
-
- var3 = this.URI2URL(var3);
- URL var10 = new URL(this.url, var3);
- this.stack.push(this.url);
- this.url = var10;
- this.systemId = var3;
- return new Source(var10.openStream());
- }
-
- public void closeInputStream(Source var1) {
- if (!this.stack.empty()) {
- this.url = (URL)this.stack.pop();
- }
-
- }
-
- public void loadCatalog(Reader var1) throws IOException {
- if (this.catalog == null) {
- this.catalog = new Hashtable();
- }
-
- BufferedReader var2 = new BufferedReader(var1);
-
- String var3;
- while((var3 = var2.readLine()) != null) {
- StringTokenizer var4 = new StringTokenizer(var3, "\t");
- if (var4.hasMoreTokens()) {
- String var5 = var4.nextToken();
- if (var4.hasMoreTokens()) {
- String var6 = var4.nextToken();
- if (var5.length() > 4 && var5.substring(0, 4).equalsIgnoreCase("urn:")) {
- this.catalog.put(Util.normalizeURN(var5), var6);
- } else {
- this.catalog.put(var5, var6);
- }
- }
- }
- }
-
- }
-
- public String getPublicId() {
- return this.publicId;
- }
-
- public String getSystemId() {
- return this.systemId;
- }
-
- static {
- printer = new PrintWriter(System.err);
- }
- }
-